package com.huilian.iotbox.admin.quartz.job;

import com.huilian.iotbox.admin.service.StatsPackageStoreService;
import com.huilian.iotbox.data.enums.StatisticsTypeEnum;
import com.huilian.iotbox.data.utils.DateTimeUtils;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author LinYinDong
 * @date 2023/7/28 14:22
 */
@Slf4j
public class StatsMonthPackageStoreJob implements BaseJob{
    @Autowired
    private StatsPackageStoreService statsPackageStoreService;
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        log.info("--------------定时任务 套餐订单月统计 统计开始 时间{}---------------", DateTimeUtils.currTime());

        //上月第一天 1970-01-01 00:00:00
        String startTime = DateTimeUtils.parseLocalDate(DateTimeUtils.getPreviousMonthFirstDay()).format(DateTimeUtils.START_DATETIME_FORMATTER);
        //上月最后一天 1970-01-30 11:59:59
        String endTime = DateTimeUtils.parseLocalDate(DateTimeUtils.getPreviousMonthLastDay()).format(DateTimeUtils.END_DATETIME_FORMATTER);
        // 上月，1970-01
        String previousMonth = DateTimeUtils.getPreviousMonth();
        statsPackageStoreService.statsMonthPackageStoreJob(startTime, endTime, previousMonth, StatisticsTypeEnum.MONTH.getCode());
        log.info("--------------定时任务 套餐订单月统计 统计结束 end时间{}---------------", DateTimeUtils.currTime());
    }
}
